package com.mxx.common.netty.interceptor;

import com.mxx.common.netty.http.NettyMethod;
import com.mxx.common.netty.http.NettyHttpRequest;
import com.mxx.common.netty.http.NettyHttpResponse;

/**
 * @Auther: Mr. Zeng
 * @Date: 2020/7/17 12:11
 * @Description: 暂无描述
 */
public interface NettyHttpInterceptor extends Comparable<NettyHttpInterceptor> {

    default Finish before(NettyHttpRequest request, NettyMethod processor) {

        return Finish.SUCCESSFUL;
    }

    default Finish complete(NettyHttpRequest request, NettyMethod processor) {
        return Finish.SUCCESSFUL;
    }

    default Finish after(NettyHttpRequest request, NettyHttpResponse response, NettyMethod processor) {
        return Finish.SUCCESSFUL;
    }

    default int sort() {
        return Integer.MIN_VALUE;
    }

    @Override
    default int compareTo(NettyHttpInterceptor o) {
        int sort = o.sort() - sort();
        if (sort == 0) {
            if (this.getClass().equals(o.getClass())) {
                return 0;
            }
            return 1;
        }
        return sort;
    }
}
